home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Sound / Playing & Recording / Macintosh Tracker / Tracker Client Folder / CMyDocument.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-07  |  51.3 KB  |  2,187 lines  |  [TEXT/KAHL]

  1. /* CMyDocument.c */
  2.  
  3. #define compilingmydocument_c
  4.  
  5. #include "CMyDocument.h"
  6. #include "MenuController.h"
  7. #include "CSaveBeforeClosing.h"
  8. #include "Memory.h"
  9. #include "CApplication.h"
  10. #include "File.h"
  11. #include "CSack.h"
  12. #include "Alert.h"
  13. #include "CArray.h"
  14. #include "PortableFile.h"
  15. #include "Error.h"
  16. #include "StandardFile.h"
  17. #include <Sound.h>
  18. #include "CSongList.h"
  19. #include "CRewindButton.h"
  20. #include "CFastForwardButton.h"
  21. #include "CStopButton.h"
  22. #include "CPlayButton.h"
  23. #include "CPauseButton.h"
  24. #include "CSkipToNextButton.h"
  25. #include "LocationConstants.h"
  26. #include "CStaticText.h"
  27. #include "StringUtils.h"
  28. #include "CCheckbox.h"
  29. #include "CNumberEdit.h"
  30. #include "CDefaultStereoOn.h"
  31. #include "CDefaultAntiAlias.h"
  32. #include "CDefaultSamplingRate.h"
  33. #include "CDefaultStereoMix.h"
  34. #include "CDefaultNumRepeats.h"
  35. #include "CDefaultSpeed.h"
  36. #include "CSpecificStereoOn.h"
  37. #include "CSpecificAntiAlias.h"
  38. #include "CSpecificSamplingRate.h"
  39. #include "CSpecificStereoMix.h"
  40. #include "CSpecificNumRepeats.h"
  41. #include "CSpecificSpeed.h"
  42. #include "COverrideStereoOn.h"
  43. #include "COverrideAntiAlias.h"
  44. #include "COverrideSamplingRate.h"
  45. #include "COverrideStereoMix.h"
  46. #include "COverrideNumRepeats.h"
  47. #include "COverrideSpeed.h"
  48. #include "CDividerLine.h"
  49. #include "CMyApplication.h"
  50. #include "CSpecificVolume.h"
  51. #include "CDefaultVolume.h"
  52. #include "COverrideVolume.h"
  53. #include "CAutoNextSong.h"
  54. #include "CRepeat.h"
  55. #include "CAutoStartSongs.h"
  56. #include "CRandomize.h"
  57. #include "CSpecificTracker.h"
  58.  
  59.  
  60. #define UntitledStringID (6592L*65536L + 1)
  61. #define SeparatorID (6592L*65536L + 2)
  62. #define EVENTDELAY (15)
  63.  
  64. #define CouldntSaveSongID (5120L*65536L + 1)
  65. #define ErrorOccurredWhileLoadingID (5120L*65536L + 2)
  66.  
  67. #define MAXRANDOMTRIESBEFOREGIVINGUP (50)
  68.  
  69.  
  70. /* */                CMyDocument::CMyDocument()
  71.     {
  72.         CArray*                SongTemp;
  73.         Handle                Temp;
  74.  
  75.         SongTemp = new CArray;
  76.         SongTemp->IArray(sizeof(SongRec),16);
  77.         ListOfSongs = SongTemp;
  78.  
  79.         RootWindow = NIL;
  80.         EverSaved = False;
  81.         UpToDate = True;
  82.         FileOpenFlag = False;
  83.  
  84.         SamplingRate = 22254;
  85.         StereoOn = False;
  86.         StereoMix = 0;
  87.         AntiAliasing = True;
  88.         Speed = 50;
  89.         NumRepeats = 1;
  90.         Volume = 48;
  91.         AutoNextSong = True;
  92.         Repeat = False;
  93.         AutoStartSongs = True;
  94.         Randomize = False;
  95.  
  96.         Selection = -1;
  97.  
  98.         SongToStart = -1;
  99.         PlayerExists = False;
  100.         PlayNextWhenThisOneStops = False;
  101.         Playing = -1;
  102.  
  103.         GetDateTime((void*)&randSeed);
  104.  
  105.         Temp = GetCString(UntitledStringID);
  106.         Handle2PString(Temp,TheFile.name);
  107.         ReleaseHandle(Temp);
  108.     }
  109.  
  110.  
  111. /* */                CMyDocument::~CMyDocument()
  112.     {
  113.         long                Scan;
  114.         SongRec            Thang;
  115.  
  116.         DeregisterIdler(this);
  117.  
  118.         if (RootWindow != NIL)
  119.             {
  120.                 delete RootWindow;
  121.             }
  122.  
  123.         for (Scan = 0; Scan < ListOfSongs->GetNumElements(); Scan += 1)
  124.             {
  125.                 ListOfSongs->GetElement(Scan,&Thang);
  126.                 ReleaseHandle((Handle)Thang.SongLocation);
  127.             }
  128.         delete ListOfSongs;
  129.  
  130.         if (FileOpenFlag)
  131.             {
  132.                 FCloseFile(FileRef);
  133.             }
  134.     }
  135.  
  136.  
  137. void                CMyDocument::DoNewFile(void)
  138.     {
  139.         MakeNewWindow();
  140.     }
  141.  
  142.  
  143. MyBoolean        CMyDocument::GoAway(void)
  144.     {
  145.         if (!UpToDate && EverSaved)
  146.             {
  147.                 CSaveBeforeClosingWindow*        Saver;
  148.                 MyBoolean                                        Result;
  149.  
  150.                 Saver = new CSaveBeforeClosingWindow;
  151.                 HLock((Handle)this);
  152.                 Result = Saver->SaveBeforeClosing(TheFile.name);
  153.                 HUnlock((Handle)this);
  154.                 switch (Result)
  155.                     {
  156.                         case Yes_Save:
  157.                             if (!SaveFile())
  158.                                 {
  159.                                     return False;
  160.                                 }
  161.                             break;
  162.                         case No_Save:
  163.                             break;
  164.                         case Cancel_Close:
  165.                             return False;
  166.                     }
  167.             }
  168.  
  169.         if (PlayerExists)
  170.             {
  171.                 Application->KillPlayer(OurPlayer);
  172.             }
  173.  
  174.         delete this;
  175.         return True;
  176.     }
  177.  
  178.  
  179. void                CMyDocument::DoPrint(void)
  180.     {
  181.     }
  182.  
  183.  
  184. void                CMyDocument::DoOpenFile(FSSpec* TheSpec)
  185.     {
  186.         short                    LocalRef;
  187.         ulong                    SongCount;
  188.  
  189.         /* reading in all them alias records */
  190.         TheFile = *TheSpec;
  191.         if (FOpenFile(TheSpec,&LocalRef) != noErr)
  192.             {
  193.                 /* error */
  194.             }
  195.         FileOpenFlag = True;
  196.         FileRef = LocalRef;
  197.  
  198.         ResetErrorCheck();
  199.         SamplingRate = (ushort)RShort(LocalRef);
  200.         StereoOn = RChar(LocalRef);
  201.         StereoMix = RShort(LocalRef);
  202.         AntiAliasing = RChar(LocalRef);
  203.         Speed = RShort(LocalRef);
  204.         NumRepeats = RShort(LocalRef);
  205.         Volume = RShort(LocalRef);
  206.         AutoNextSong = RChar(LocalRef);
  207.         Repeat = RChar(LocalRef);
  208.         AutoStartSongs = RChar(LocalRef);
  209.         Randomize = RChar(LocalRef);
  210.  
  211.         SongCount = RShort(LocalRef);
  212.         while (SongCount > 0)
  213.             {
  214.                 ulong                        AliasLength;
  215.                 SongRec                    DaAlias;
  216.                 long                        NewEntry;
  217.  
  218.                 DaAlias.SamplingRateOverrideDefault = RChar(LocalRef);
  219.                 DaAlias.SamplingRate = (ushort)RShort(LocalRef);
  220.                 DaAlias.StereoOnOverrideDefault = RChar(LocalRef);
  221.                 DaAlias.StereoOn = RShort(LocalRef);
  222.                 DaAlias.StereoMixOverrideDefault = RChar(LocalRef);
  223.                 DaAlias.StereoMix = RShort(LocalRef);
  224.                 DaAlias.AntiAliasingOverrideDefault = RChar(LocalRef);
  225.                 DaAlias.AntiAliasing = RShort(LocalRef);
  226.                 DaAlias.SpeedOverrideDefault = RChar(LocalRef);
  227.                 DaAlias.Speed = RShort(LocalRef);
  228.                 DaAlias.NumRepeatsOverrideDefault = RChar(LocalRef);
  229.                 DaAlias.NumRepeats = RShort(LocalRef);
  230.                 DaAlias.VolumeOverrideDefault = RChar(LocalRef);
  231.                 DaAlias.Volume = RShort(LocalRef);
  232.                 DaAlias.Tracker = RChar(LocalRef);
  233.                 FReadBlock(LocalRef,(char*)DaAlias.SongName,SongNameLength);
  234.                 AliasLength = RLong(LocalRef);
  235.                 DaAlias.SongLocation = (AliasRecord**)AllocHandle(AliasLength);
  236.                 HLock((Handle)DaAlias.SongLocation);
  237.                 FReadBlock(LocalRef,(char*)*DaAlias.SongLocation,AliasLength);
  238.                 HUnlock((Handle)DaAlias.SongLocation);
  239.                 DaAlias.PlayedFlag = False;
  240.                 NewEntry = ListOfSongs->AppendElement();
  241.                 ListOfSongs->PutElement(NewEntry,&DaAlias);
  242.                 SongCount -= 1;
  243.             }
  244.         if (ErrorOccurred())
  245.             {
  246.                 AlertError(ErrorOccurredWhileLoadingID,NIL);
  247.             }
  248.         MakeNewWindow();
  249.         SongList->RecalculateScrollBars();
  250.         if ((LastModifiers & controlKey) == 0)
  251.             {
  252.                 /* if they were NOT holding down the control key, then we want */
  253.                 /* to see if they are now.  Otherwise, we don't want to clear it. */
  254.                 RelinquishCPU();
  255.             }
  256.         if (AutoStartSongs && ((LastModifiers & controlKey) == 0))
  257.             {
  258.                 /* if they want to autostart songs upon opening the document AND */
  259.                 /* they didn't hold down the command key while selecting "open" */
  260.                 /* (or starting the program) then we can do it. */
  261.                 if (Randomize)
  262.                     {
  263.                         StartRandomSong();
  264.                     }
  265.                  else
  266.                     {
  267.                         StartThisSong(0);
  268.                     }
  269.             }
  270.         EverSaved = True;
  271.     }
  272.  
  273.  
  274. MyBoolean        CMyDocument::SaveFile(void)
  275.     {
  276.         if (EverSaved)
  277.             {
  278.                 WriteData();
  279.                 return True;
  280.             }
  281.          else
  282.             {
  283.                 return SaveFileAs();
  284.             }
  285.     }
  286.  
  287.  
  288. MyBoolean        CMyDocument::SaveFileAs(void)
  289.     {
  290.         FSSpec            NewInfo;
  291.         MyBoolean        Result;
  292.         MyBoolean        Replacing;
  293.  
  294.         HLock((Handle)this);
  295.         Result = FPutFile(TheFile.name,&NewInfo,&Replacing);
  296.         if (Result)
  297.             {
  298.                 if (Replacing)
  299.                     {
  300.                         FDeleteFile(&NewInfo);
  301.                     }
  302.                 TheFile = NewInfo;
  303.                 FCreate(&NewInfo,CREATORCODE,FILETYPE1);
  304.                 FOpenFile(&NewInfo,&FileRef);
  305.                 FileOpenFlag = True;
  306.                 WriteData();
  307.                 EverSaved = True;
  308.                 SetWTitle(RootWindow->MyGrafPtr,TheFile.name);
  309.             }
  310.         HUnlock((Handle)this);
  311.         return Result;
  312.     }
  313.  
  314.  
  315. void                CMyDocument::WriteData(void)
  316.     {
  317.         ulong                    SongCount;
  318.         ulong                    SongScan;
  319.         long                    FilePosTemp;
  320.  
  321.         ERROR(!FileOpenFlag,PRERR(ForceAbort,"CMyDocument::WriteData called when "
  322.             "no file was open for writing."));
  323.  
  324.         SpecificSamplingRateBox->StoreValue();
  325.         SpecificStereoMixBox->StoreValue();
  326.         SpecificNumRepeatsBox->StoreValue();
  327.         SpecificSpeedBox->StoreValue();
  328.         SpecificVolumeBox->StoreValue();
  329.         DefaultSamplingRateBox->StoreValue();
  330.         DefaultStereoMixBox->StoreValue();
  331.         DefaultNumRepeatsBox->StoreValue();
  332.         DefaultSpeedBox->StoreValue();
  333.         DefaultVolumeBox->StoreValue();
  334.  
  335.         ResetErrorCheck();
  336.         FSetFilePos(FileRef,0);
  337.  
  338.         WShort(FileRef,SamplingRate);
  339.         WChar(FileRef,StereoOn);
  340.         WShort(FileRef,StereoMix);
  341.         WChar(FileRef,AntiAliasing);
  342.         WShort(FileRef,Speed);
  343.         WShort(FileRef,NumRepeats);
  344.         WShort(FileRef,Volume);
  345.         WChar(FileRef,AutoNextSong);
  346.         WChar(FileRef,Repeat);
  347.         WChar(FileRef,AutoStartSongs);
  348.         WChar(FileRef,Randomize);
  349.  
  350.         SongCount = ListOfSongs->GetNumElements();
  351.         WShort(FileRef,SongCount);
  352.         for (SongScan = 0; SongScan < SongCount; SongScan += 1)
  353.             {
  354.                 SongRec            Song;
  355.                 ulong                AliasSize;
  356.  
  357.                 ListOfSongs->GetElement(SongScan,&Song);
  358.                 WChar(FileRef,Song.SamplingRateOverrideDefault);
  359.                 WShort(FileRef,Song.SamplingRate);
  360.                 WChar(FileRef,Song.StereoOnOverrideDefault);
  361.                 WShort(FileRef,Song.StereoOn);
  362.                 WChar(FileRef,Song.StereoMixOverrideDefault);
  363.                 WShort(FileRef,Song.StereoMix);
  364.                 WChar(FileRef,Song.AntiAliasingOverrideDefault);
  365.                 WShort(FileRef,Song.AntiAliasing);
  366.                 WChar(FileRef,Song.SpeedOverrideDefault);
  367.                 WShort(FileRef,Song.Speed);
  368.                 WChar(FileRef,Song.NumRepeatsOverrideDefault);
  369.                 WShort(FileRef,Song.NumRepeats);
  370.                 WChar(FileRef,Song.VolumeOverrideDefault);
  371.                 WShort(FileRef,Song.Volume);
  372.                 WChar(FileRef,Song.Tracker);
  373.                 FWriteBlock(FileRef,(char*)Song.SongName,SongNameLength);
  374.                 AliasSize = HandleSize((Handle)Song.SongLocation);
  375.                 WLong(FileRef,AliasSize);
  376.                 HLock((Handle)Song.SongLocation);
  377.                 FWriteBlock(FileRef,(char*)*Song.SongLocation,AliasSize);
  378.                 HUnlock((Handle)Song.SongLocation);
  379.             }
  380.         FGetFilePos(FileRef,&FilePosTemp);
  381.         FSetEOF(FileRef,FilePosTemp);
  382.         if (ErrorOccurred())
  383.             {
  384.                 AlertError(CouldntSaveSongID,NIL);
  385.             }
  386.          else
  387.             {
  388.                 UpToDate = True;
  389.             }
  390.     }
  391.  
  392.  
  393. void                CMyDocument::AddSong(FSSpec* TheSpec)
  394.     {
  395.         AliasRecord**            SystemAlias;
  396.         SongRec                        MyAlias;
  397.         long                            IndexToStoreAt;
  398.         OSErr                            Error;
  399.         short                            Scan;
  400.  
  401.         for (Scan = 0; Scan < sizeof(MyAlias); Scan += 1)
  402.             {
  403.                 ((char*)&MyAlias)[Scan] = 0;
  404.             }
  405.         MyAlias.SamplingRateOverrideDefault = False;
  406.         MyAlias.StereoOnOverrideDefault = False;
  407.         MyAlias.StereoMixOverrideDefault = False;
  408.         MyAlias.AntiAliasingOverrideDefault = False;
  409.         MyAlias.SpeedOverrideDefault = False;
  410.         MyAlias.NumRepeatsOverrideDefault = False;
  411.         MyAlias.VolumeOverrideDefault = False;
  412.         MyAlias.SamplingRate = SamplingRate;
  413.         MyAlias.StereoOn = StereoOn;
  414.         MyAlias.StereoMix = StereoMix;
  415.         MyAlias.AntiAliasing = AntiAliasing;
  416.         MyAlias.Speed = Speed;
  417.         MyAlias.NumRepeats = NumRepeats;
  418.         MyAlias.Volume = Volume;
  419.         MyAlias.Tracker = False;
  420.         MemCpy((char*)MyAlias.SongName,(char*)TheSpec->name,TheSpec->name[0] + 1);
  421.         if (MyAlias.SongName[0] > SongNameLength - 1)
  422.             {
  423.                 MyAlias.SongName[0] = SongNameLength - 1;
  424.             }
  425.         Error = NewAlias(NIL,TheSpec,&SystemAlias);
  426.         MyAlias.SongLocation = (AliasRecord**)DupSysHandle((Handle)SystemAlias);
  427.         DisposHandle((Handle)SystemAlias);
  428.         MyAlias.PlayedFlag = False;
  429.         IndexToStoreAt = ListOfSongs->AppendElement();
  430.         ListOfSongs->PutElement(IndexToStoreAt,&MyAlias);
  431.         EXECUTE(ListOfSongs->GetElement(IndexToStoreAt,&MyAlias);)
  432.         SongList->Redraw(IndexToStoreAt,IndexToStoreAt);
  433.         SongList->RecalculateScrollBars();
  434.         if ((LastModifiers & controlKey) == 0)
  435.             {
  436.                 /* if they were NOT holding down the control key, then we want */
  437.                 /* to see if they are now.  Otherwise, we don't want to clear it. */
  438.                 RelinquishCPU();
  439.             }
  440.         if ((Playing == -1) && (SongToStart == -1) && AutoStartSongs
  441.             && ((LastModifiers & controlKey) == 0))
  442.             {
  443.                 StartThisSong(IndexToStoreAt);
  444.             }
  445.         UpToDate = False;
  446.     }
  447.  
  448.  
  449. void                CMyDocument::CancelCurrentSong(void)
  450.     {
  451.         if (PlayerExists)
  452.             {
  453.                 Application->KillPlayer(OurPlayer);
  454.                 PlayerState = PlayerDying;
  455.             }
  456.         PlayNextWhenThisOneStops = False;
  457.     }
  458.  
  459.  
  460. void                CMyDocument::StartThisSong(long SongIndex)
  461.     {
  462.         SongRec                    Temp;
  463.  
  464.         if (Playing != -1)
  465.             {
  466.                 CancelCurrentSong();
  467.             }
  468.         if ((SongIndex >= 0) && (SongIndex < ListOfSongs->GetNumElements()))
  469.             {
  470.                 RegisterIdler(this,EVENTDELAY);
  471.                 SongToStart = SongIndex;
  472.                 ListOfSongs->GetElement(SongIndex,&Temp);
  473.                 Temp.PlayedFlag = True;
  474.                 ListOfSongs->PutElement(SongIndex,&Temp);
  475.             }
  476.         PlayNextWhenThisOneStops = AutoNextSong;
  477.     }
  478.  
  479.  
  480. void                CMyDocument::RemoveSongFromList(long SongIndex)
  481.     {
  482.         SongRec                Temp;
  483.  
  484.         if ((SongIndex >= 0) && (SongIndex < ListOfSongs->GetNumElements()))
  485.             {
  486.                 if (SongIndex == Playing)
  487.                     {
  488.                         CancelCurrentSong();
  489.                     }
  490.                 if (SongIndex < Playing)
  491.                     {
  492.                         Playing -= 1;
  493.                     }
  494.                 UpToDate = False;
  495.                 ListOfSongs->GetElement(SongIndex,&Temp);
  496.                 ReleaseHandle((Handle)Temp.SongLocation);
  497.                 ListOfSongs->DeleteElement(SongIndex);
  498.                 SongList->Redraw(SongIndex,ListOfSongs->GetNumElements());
  499.             }
  500.     }
  501.  
  502.  
  503. void                CMyDocument::MakeNewWindow(void)
  504.     {
  505.         CWindow*                        Window;
  506.         LongPoint                        Start;
  507.         LongPoint                        Extent;
  508.         CStaticText*                StaticText;
  509.         CPlayButton*                PlayButton;
  510.         CDividerLine*                DividerLine;
  511.  
  512.  
  513.         MoveHHi((Handle)this);
  514.         HLock((Handle)this);
  515.  
  516.  
  517.         Window = new CWindow;
  518.         GetRect(WindowLocsID,&Start,&Extent);
  519.         Start = CenterRect(Extent,MainScreenSize());
  520.         Window->IWindow(Start,Extent,ModelessWindow,NoGrowable,NoZoomable);
  521.         RootWindow = Window;
  522.         SetWTitle(Window->MyGrafPtr,TheFile.name);
  523.  
  524.  
  525.         SongList = new CSongList;
  526.         SongList->ISongList(this,Window);
  527.  
  528.  
  529.         RewindButton = new CRewindButton;
  530.         RewindButton->IRewindButton(this,Window);
  531.  
  532.         StopButton = new CStopButton;
  533.         StopButton->IStopButton(this,Window);
  534.  
  535.         PlayButton = new CPlayButton;
  536.         PlayButton->IPlayButton(this,Window);
  537.         PausePlayButton = PlayButton;
  538.  
  539.         FastForwardButton = new CFastForwardButton;
  540.         FastForwardButton->IFastForwardButton(this,Window);
  541.  
  542.         SkipToNextButton = new CSkipToNextButton;
  543.         SkipToNextButton->ISkipToNextButton(this,Window);
  544.  
  545.  
  546.         StaticText = new CStaticText;
  547.         GetRect(DefaultSettingsID,&Start,&Extent);
  548.         StaticText->IStaticText(Start,Extent,GetCString(DefaultSettingsID),
  549.             applFont,9,Window,Window,JustifyLeft);
  550.  
  551.         StaticText = new CStaticText;
  552.         GetRect(DefaultFrequencyID,&Start,&Extent);
  553.         StaticText->IStaticText(Start,Extent,GetCString(DefaultFrequencyID),
  554.             applFont,9,Window,Window,JustifyLeft);
  555.  
  556.         StaticText = new CStaticText;
  557.         GetRect(DefaultSpeedID,&Start,&Extent);
  558.         StaticText->IStaticText(Start,Extent,GetCString(DefaultSpeedID),
  559.             applFont,9,Window,Window,JustifyLeft);
  560.  
  561.         StaticText = new CStaticText;
  562.         GetRect(DefaultRepeatsID,&Start,&Extent);
  563.         StaticText->IStaticText(Start,Extent,GetCString(DefaultRepeatsID),
  564.             applFont,9,Window,Window,JustifyLeft);
  565.  
  566.         StaticText = new CStaticText;
  567.         GetRect(DefaultMixID,&Start,&Extent);
  568.         StaticText->IStaticText(Start,Extent,GetCString(DefaultMixID),
  569.             applFont,9,Window,Window,JustifyLeft);
  570.  
  571.         StaticText = new CStaticText;
  572.         GetRect(DefaultVolumeID,&Start,&Extent);
  573.         StaticText->IStaticText(Start,Extent,GetCString(DefaultVolumeID),
  574.             applFont,9,Window,Window,JustifyLeft);
  575.  
  576.         SpecificSamplingRateText = new CStaticText;
  577.         GetRect(SpecificFrequencyID,&Start,&Extent);
  578.         SpecificSamplingRateText->IStaticText(Start,Extent,GetCString(SpecificFrequencyID),
  579.             applFont,9,Window,Window,JustifyLeft);
  580.  
  581.         SpecificSpeedText = new CStaticText;
  582.         GetRect(SpecificSpeedID,&Start,&Extent);
  583.         SpecificSpeedText->IStaticText(Start,Extent,GetCString(SpecificSpeedID),
  584.             applFont,9,Window,Window,JustifyLeft);
  585.  
  586.         SpecificNumRepeatsText = new CStaticText;
  587.         GetRect(SpecificRepeatsID,&Start,&Extent);
  588.         SpecificNumRepeatsText->IStaticText(Start,Extent,GetCString(SpecificRepeatsID),
  589.             applFont,9,Window,Window,JustifyLeft);
  590.  
  591.         SpecificStereoMixText = new CStaticText;
  592.         GetRect(SpecificMixID,&Start,&Extent);
  593.         SpecificStereoMixText->IStaticText(Start,Extent,GetCString(SpecificMixID),
  594.             applFont,9,Window,Window,JustifyLeft);
  595.  
  596.         SpecificVolumeText = new CStaticText;
  597.         GetRect(SpecificVolumeID,&Start,&Extent);
  598.         SpecificVolumeText->IStaticText(Start,Extent,GetCString(SpecificVolumeID),
  599.             applFont,9,Window,Window,JustifyLeft);
  600.  
  601.         AutoNextSongBox = new CAutoNextSong;
  602.         AutoNextSongBox->IAutoNextSong(this,Window);
  603.  
  604.         RepeatBox = new CRepeat;
  605.         RepeatBox->IRepeat(this,Window);
  606.  
  607.         AutoStartSongsBox = new CAutoStartSongs;
  608.         AutoStartSongsBox->IAutoStartSongs(this,Window);
  609.  
  610.         RandomizeBox = new CRandomize;
  611.         RandomizeBox->IRandomize(this,Window);
  612.  
  613.         DividerLine = new CDividerLine;
  614.         DividerLine->IDividerLine(Window);
  615.  
  616.  
  617.         DefaultStereoOnBox = new CDefaultStereoOn;
  618.         DefaultStereoOnBox->IDefaultStereoOn(this,Window);
  619.  
  620.         DefaultAntiAliasingBox = new CDefaultAntiAliasing;
  621.         DefaultAntiAliasingBox->IDefaultAntiAliasing(this,Window);
  622.  
  623.         DefaultVolumeBox = new CDefaultVolume;
  624.         DefaultVolumeBox->IDefaultVolume(this,Window);
  625.         DefaultVolumeBox->SetValue(Volume);
  626.  
  627.         DefaultSamplingRateBox = new CDefaultSamplingRate;
  628.         DefaultSamplingRateBox->IDefaultSamplingRate(this,Window);
  629.         DefaultSamplingRateBox->SetValue(SamplingRate);
  630.  
  631.         DefaultSpeedBox = new CDefaultSpeed;
  632.         DefaultSpeedBox->IDefaultSpeed(this,Window);
  633.         DefaultSpeedBox->SetValue(Speed);
  634.  
  635.         DefaultNumRepeatsBox = new CDefaultNumRepeats;
  636.         DefaultNumRepeatsBox->IDefaultNumRepeats(this,Window);
  637.         DefaultNumRepeatsBox->SetValue(NumRepeats);
  638.  
  639.         DefaultStereoMixBox = new CDefaultStereoMix;
  640.         DefaultStereoMixBox->IDefaultStereoMix(this,Window);
  641.         DefaultStereoMixBox->SetValue(StereoMix);
  642.  
  643.  
  644.         SpecificStereoOnBox = new CSpecificStereoOn;
  645.         SpecificStereoOnBox->ISpecificStereoOn(this,Window);
  646.  
  647.         SpecificAntiAliasingBox = new CSpecificAntiAliasing;
  648.         SpecificAntiAliasingBox->ISpecificAntiAliasing(this,Window);
  649.  
  650.         SpecificVolumeBox = new CSpecificVolume;
  651.         SpecificVolumeBox->ISpecificVolume(this,Window);
  652.  
  653.         SpecificSamplingRateBox = new CSpecificSamplingRate;
  654.         SpecificSamplingRateBox->ISpecificSamplingRate(this,Window);
  655.  
  656.         SpecificSpeedBox = new CSpecificSpeed;
  657.         SpecificSpeedBox->ISpecificSpeed(this,Window);
  658.  
  659.         SpecificNumRepeatsBox = new CSpecificNumRepeats;
  660.         SpecificNumRepeatsBox->ISpecificNumRepeats(this,Window);
  661.  
  662.         SpecificStereoMixBox = new CSpecificStereoMix;
  663.         SpecificStereoMixBox->ISpecificStereoMix(this,Window);
  664.  
  665.         SpecificTrackerBox = new CSpecificTracker;
  666.         SpecificTrackerBox->ISpecificTracker(this,Window);
  667.  
  668.  
  669.         OverrideStereoOnBox = new COverrideStereoOn;
  670.         OverrideStereoOnBox->IOverrideStereoOn(this,Window);
  671.  
  672.         OverrideAntiAliasingBox = new COverrideAntiAliasing;
  673.         OverrideAntiAliasingBox->IOverrideAntiAliasing(this,Window);
  674.  
  675.         OverrideSamplingRateBox = new COverrideSamplingRate;
  676.         OverrideSamplingRateBox->IOverrideSamplingRate(this,Window);
  677.  
  678.         OverrideStereoMixBox = new COverrideStereoMix;
  679.         OverrideStereoMixBox->IOverrideStereoMix(this,Window);
  680.  
  681.         OverrideNumRepeatsBox = new COverrideNumRepeats;
  682.         OverrideNumRepeatsBox->IOverrideNumRepeats(this,Window);
  683.  
  684.         OverrideSpeedBox = new COverrideSpeed;
  685.         OverrideSpeedBox->IOverrideSpeed(this,Window);
  686.  
  687.         OverrideVolumeBox = new COverrideVolume;
  688.         OverrideVolumeBox->IOverrideVolume(this,Window);
  689.  
  690.  
  691.         SpecificStereoOnBox->DoDisable();
  692.         SpecificAntiAliasingBox->DoDisable();
  693.         SpecificSamplingRateBox->DoDisable();
  694.         SpecificStereoMixBox->DoDisable();
  695.         SpecificNumRepeatsBox->DoDisable();
  696.         SpecificSpeedBox->DoDisable();
  697.         SpecificVolumeBox->DoDisable();
  698.         SpecificTrackerBox->DoDisable();
  699.         SpecificSamplingRateText->DoDisable();
  700.         SpecificStereoMixText->DoDisable();
  701.         SpecificNumRepeatsText->DoDisable();
  702.         SpecificSpeedText->DoDisable();
  703.         SpecificVolumeText->DoDisable();
  704.  
  705.         OverrideStereoOnBox->DoDisable();
  706.         OverrideAntiAliasingBox->DoDisable();
  707.         OverrideSamplingRateBox->DoDisable();
  708.         OverrideStereoMixBox->DoDisable();
  709.         OverrideNumRepeatsBox->DoDisable();
  710.         OverrideSpeedBox->DoDisable();
  711.         OverrideVolumeBox->DoDisable();
  712.  
  713.         if (StereoOn)
  714.             {
  715.                 DefaultStereoOnBox->DoThang();
  716.             }
  717.  
  718.         if (AntiAliasing)
  719.             {
  720.                 DefaultAntiAliasingBox->DoThang();
  721.             }
  722.  
  723.         if (AutoNextSong)
  724.             {
  725.                 AutoNextSongBox->DoThang();
  726.             }
  727.  
  728.         if (Repeat)
  729.             {
  730.                 RepeatBox->DoThang();
  731.             }
  732.  
  733.         if (AutoStartSongs)
  734.             {
  735.                 AutoStartSongsBox->DoThang();
  736.             }
  737.  
  738.         if (Randomize)
  739.             {
  740.                 RandomizeBox->DoThang();
  741.             }
  742.  
  743.         RewindButton->DoDisable();
  744.         StopButton->DoDisable();
  745.         PausePlayButton->DoEnable();
  746.         FastForwardButton->DoDisable();
  747.         SkipToNextButton->DoDisable();
  748.  
  749.  
  750.         HUnlock((Handle)this);
  751.     }
  752.  
  753.  
  754. void                CMyDocument::SetStereoOn(MyBoolean NewStereoOn)
  755.     {
  756.         SongRec                Temp;
  757.  
  758.         if (Selection == -1)
  759.             {
  760.                 return;
  761.             }
  762.  
  763.         UpToDate = False;
  764.         ListOfSongs->GetElement(Selection,&Temp);
  765.         Temp.StereoOn = NewStereoOn;
  766.         ListOfSongs->PutElement(Selection,&Temp);
  767.         if (SpecificStereoOnBox->State != NewStereoOn)
  768.             {
  769.                 SpecificStereoOnBox->DoThang();
  770.             }
  771.         if (Selection == Playing)
  772.             {
  773.                 SendMessage((short)NewStereoOn,keyStereoOn);
  774.             }
  775.     }
  776.  
  777.  
  778. void                CMyDocument::SetSpecificTracker(MyBoolean UseFrankSeide)
  779.     {
  780.         SongRec                Temp;
  781.  
  782.         if (Selection == -1)
  783.             {
  784.                 return;
  785.             }
  786.  
  787.         UpToDate = False;
  788.         ListOfSongs->GetElement(Selection,&Temp);
  789.         Temp.Tracker = UseFrankSeide;
  790.         ListOfSongs->PutElement(Selection,&Temp);
  791.         if (SpecificTrackerBox->State != UseFrankSeide)
  792.             {
  793.                 SpecificTrackerBox->DoThang();
  794.             }
  795.     }
  796.  
  797.  
  798. void                CMyDocument::SetAntiAliasing(MyBoolean NewAntiAliasing)
  799.     {
  800.         SongRec                Temp;
  801.  
  802.         if (Selection == -1)
  803.             {
  804.                 return;
  805.             }
  806.  
  807.         UpToDate = False;
  808.         ListOfSongs->GetElement(Selection,&Temp);
  809.         Temp.AntiAliasing = NewAntiAliasing;
  810.         ListOfSongs->PutElement(Selection,&Temp);
  811.         if (SpecificAntiAliasingBox->State != NewAntiAliasing)
  812.             {
  813.                 SpecificAntiAliasingBox->DoThang();
  814.             }
  815.         if (Selection == Playing)
  816.             {
  817.                 SendMessage((short)NewAntiAliasing,keyAntiAliasing);
  818.             }
  819.     }
  820.  
  821.  
  822. void                CMyDocument::SetSamplingRate(ulong NewSamplingRate)
  823.     {
  824.         SongRec                Temp;
  825.  
  826.         if (Selection == -1)
  827.             {
  828.                 return;
  829.             }
  830.  
  831.         UpToDate = False;
  832.         ListOfSongs->GetElement(Selection,&Temp);
  833.         Temp.SamplingRate = NewSamplingRate;
  834.         ListOfSongs->PutElement(Selection,&Temp);
  835.         SpecificSamplingRateBox->SetValue(NewSamplingRate);
  836.         if (Selection == Playing)
  837.             {
  838.                 SendMessage((short)NewSamplingRate,keySamplingRate);
  839.             }
  840.     }
  841.  
  842.  
  843. void                CMyDocument::SetStereoMix(short NewStereoMix)
  844.     {
  845.         SongRec                Temp;
  846.  
  847.         if (Selection == -1)
  848.             {
  849.                 return;
  850.             }
  851.  
  852.         UpToDate = False;
  853.         ListOfSongs->GetElement(Selection,&Temp);
  854.         Temp.StereoMix = NewStereoMix;
  855.         ListOfSongs->PutElement(Selection,&Temp);
  856.         SpecificStereoMixBox->SetValue(NewStereoMix);
  857.         if (Selection == Playing)
  858.             {
  859.                 SendMessage((short)NewStereoMix,keyStereoMix);
  860.             }
  861.     }
  862.  
  863.  
  864. void                CMyDocument::SetNumRepeats(short NewNumRepeats)
  865.     {
  866.         SongRec                Temp;
  867.  
  868.         if (Selection == -1)
  869.             {
  870.                 return;
  871.             }
  872.  
  873.         UpToDate = False;
  874.         ListOfSongs->GetElement(Selection,&Temp);
  875.         Temp.NumRepeats = NewNumRepeats;
  876.         ListOfSongs->PutElement(Selection,&Temp);
  877.         SpecificNumRepeatsBox->SetValue(NewNumRepeats);
  878.         if (Selection == Playing)
  879.             {
  880.                 SendMessage((short)NewNumRepeats,keyNumRepeats);
  881.             }
  882.     }
  883.  
  884.  
  885. void                CMyDocument::SetSpeed(short NewSpeed)
  886.     {
  887.         SongRec                Temp;
  888.  
  889.         if (Selection == -1)
  890.             {
  891.                 return;
  892.             }
  893.  
  894.         UpToDate = False;
  895.         ListOfSongs->GetElement(Selection,&Temp);
  896.         Temp.Speed = NewSpeed;
  897.         ListOfSongs->PutElement(Selection,&Temp);
  898.         SpecificSpeedBox->SetValue(NewSpeed);
  899.         if (Selection == Playing)
  900.             {
  901.                 SendMessage((short)NewSpeed,keySpeed);
  902.             }
  903.     }
  904.  
  905.  
  906. void                CMyDocument::SetVolume(short NewVolume)
  907.     {
  908.         SongRec                Temp;
  909.  
  910.         if (Selection == -1)
  911.             {
  912.                 return;
  913.             }
  914.  
  915.         UpToDate = False;
  916.         ListOfSongs->GetElement(Selection,&Temp);
  917.         Temp.Volume = NewVolume;
  918.         ListOfSongs->PutElement(Selection,&Temp);
  919.         SpecificVolumeBox->SetValue(NewVolume);
  920.         if (Selection == Playing)
  921.             {
  922.                 SendMessage((short)NewVolume,keyLoudness);
  923.             }
  924.     }
  925.  
  926.  
  927. void                CMyDocument::SetOverrideStereoOn(MyBoolean Flag)
  928.     {
  929.         SongRec                Temp;
  930.  
  931.         if (Selection == -1)
  932.             {
  933.                 return;
  934.             }
  935.  
  936.         UpToDate = False;
  937.         ListOfSongs->GetElement(Selection,&Temp);
  938.         Temp.StereoOnOverrideDefault = Flag;
  939.         if (Flag)
  940.             {
  941.                 Temp.StereoOn = StereoOn;
  942.                 SpecificStereoOnBox->DoEnable();
  943.                 if (SpecificStereoOnBox->State != Temp.StereoOn)
  944.                     {
  945.                         SpecificStereoOnBox->DoThang();
  946.                     }
  947.             }
  948.          else
  949.             {
  950.                 SpecificStereoOnBox->DoDisable();
  951.                 if (Selection == Playing)
  952.                     {
  953.                         SendMessage((short)StereoOn,keyStereoOn);
  954.                     }
  955.             }
  956.         ListOfSongs->PutElement(Selection,&Temp);
  957.     }
  958.  
  959.  
  960. void                CMyDocument::SetOverrideAntiAliasing(MyBoolean Flag)
  961.     {
  962.         SongRec                Temp;
  963.  
  964.         if (Selection == -1)
  965.             {
  966.                 return;
  967.             }
  968.  
  969.         UpToDate = False;
  970.         ListOfSongs->GetElement(Selection,&Temp);
  971.         Temp.AntiAliasingOverrideDefault = Flag;
  972.         if (Flag)
  973.             {
  974.                 Temp.AntiAliasing = AntiAliasing;
  975.                 SpecificAntiAliasingBox->DoEnable();
  976.                 if (SpecificAntiAliasingBox->State != Temp.AntiAliasing)
  977.                     {
  978.                         SpecificAntiAliasingBox->DoThang();
  979.                     }
  980.             }
  981.          else
  982.             {
  983.                 SpecificAntiAliasingBox->DoDisable();
  984.                 if (Selection == Playing)
  985.                     {
  986.                         SendMessage((short)AntiAliasing,keyAntiAliasing);
  987.                     }
  988.             }
  989.         ListOfSongs->PutElement(Selection,&Temp);
  990.     }
  991.  
  992.  
  993. void                CMyDocument::SetOverrideSamplingRate(MyBoolean Flag)
  994.     {
  995.         SongRec                Temp;
  996.  
  997.         if (Selection == -1)
  998.             {
  999.                 return;
  1000.             }
  1001.  
  1002.         UpToDate = False;
  1003.         ListOfSongs->GetElement(Selection,&Temp);
  1004.         Temp.SamplingRateOverrideDefault = Flag;
  1005.         if (Flag)
  1006.             {
  1007.                 Temp.SamplingRate = SamplingRate;
  1008.                 SpecificSamplingRateBox->DoEnable();
  1009.                 SpecificSamplingRateText->DoEnable();
  1010.                 if (SpecificSamplingRateBox->GetValue() != Temp.SamplingRate)
  1011.                     {
  1012.                         SpecificSamplingRateBox->SetValue(Temp.SamplingRate);
  1013.                     }
  1014.             }
  1015.          else
  1016.             {
  1017.                 SpecificSamplingRateBox->DoDisable();
  1018.                 SpecificSamplingRateText->DoDisable();
  1019.                 if (Selection == Playing)
  1020.                     {
  1021.                         SendMessage((short)SamplingRate,keySamplingRate);
  1022.                     }
  1023.             }
  1024.         ListOfSongs->PutElement(Selection,&Temp);
  1025.     }
  1026.  
  1027.  
  1028. void                CMyDocument::SetOverrideStereoMix(MyBoolean Flag)
  1029.     {
  1030.         SongRec                Temp;
  1031.  
  1032.         if (Selection == -1)
  1033.             {
  1034.                 return;
  1035.             }
  1036.  
  1037.         UpToDate = False;
  1038.         ListOfSongs->GetElement(Selection,&Temp);
  1039.         Temp.StereoMixOverrideDefault = Flag;
  1040.         if (Flag)
  1041.             {
  1042.                 Temp.StereoMix = StereoMix;
  1043.                 SpecificStereoMixBox->DoEnable();
  1044.                 SpecificStereoMixText->DoEnable();
  1045.                 if (SpecificStereoMixBox->GetValue() != Temp.StereoMix)
  1046.                     {
  1047.                         SpecificStereoMixBox->SetValue(Temp.StereoMix);
  1048.                     }
  1049.             }
  1050.          else
  1051.             {
  1052.                 SpecificStereoMixBox->DoDisable();
  1053.                 SpecificStereoMixText->DoDisable();
  1054.                 if (Selection == Playing)
  1055.                     {
  1056.                         SendMessage((short)StereoMix,keyStereoMix);
  1057.                     }
  1058.             }
  1059.         ListOfSongs->PutElement(Selection,&Temp);
  1060.     }
  1061.  
  1062.  
  1063. void                CMyDocument::SetOverrideNumRepeats(MyBoolean Flag)
  1064.     {
  1065.         SongRec                Temp;
  1066.  
  1067.         if (Selection == -1)
  1068.             {
  1069.                 return;
  1070.             }
  1071.  
  1072.         UpToDate = False;
  1073.         ListOfSongs->GetElement(Selection,&Temp);
  1074.         Temp.NumRepeatsOverrideDefault = Flag;
  1075.         if (Flag)
  1076.             {
  1077.                 Temp.NumRepeats = NumRepeats;
  1078.                 SpecificNumRepeatsBox->DoEnable();
  1079.                 SpecificNumRepeatsText->DoEnable();
  1080.                 if (SpecificNumRepeatsBox->GetValue() != Temp.NumRepeats)
  1081.                     {
  1082.                         SpecificNumRepeatsBox->SetValue(Temp.NumRepeats);
  1083.                     }
  1084.             }
  1085.          else
  1086.             {
  1087.                 SpecificNumRepeatsBox->DoDisable();
  1088.                 SpecificNumRepeatsText->DoDisable();
  1089.                 if (Selection == Playing)
  1090.                     {
  1091.                         SendMessage((short)NumRepeats,keyNumRepeats);
  1092.                     }
  1093.             }
  1094.         ListOfSongs->PutElement(Selection,&Temp);
  1095.     }
  1096.  
  1097.  
  1098. void                CMyDocument::SetOverrideSpeed(MyBoolean Flag)
  1099.     {
  1100.         SongRec                Temp;
  1101.  
  1102.         if (Selection == -1)
  1103.             {
  1104.                 return;
  1105.             }
  1106.  
  1107.         UpToDate = False;
  1108.         ListOfSongs->GetElement(Selection,&Temp);
  1109.         Temp.SpeedOverrideDefault = Flag;
  1110.         if (Flag)
  1111.             {
  1112.                 Temp.Speed = Speed;
  1113.                 SpecificSpeedBox->DoEnable();
  1114.                 SpecificSpeedText->DoEnable();
  1115.                 if (SpecificSpeedBox->GetValue() != Temp.Speed)
  1116.                     {
  1117.                         SpecificSpeedBox->SetValue(Temp.Speed);
  1118.                     }
  1119.             }
  1120.          else
  1121.             {
  1122.                 SpecificSpeedBox->DoDisable();
  1123.                 SpecificSpeedText->DoDisable();
  1124.                 if (Selection == Playing)
  1125.                     {
  1126.                         SendMessage((short)Speed,keySpeed);
  1127.                     }
  1128.             }
  1129.         ListOfSongs->PutElement(Selection,&Temp);
  1130.     }
  1131.  
  1132.  
  1133. void                CMyDocument::SetOverrideVolume(MyBoolean Flag)
  1134.     {
  1135.         SongRec                Temp;
  1136.  
  1137.         if (Selection == -1)
  1138.             {
  1139.                 return;
  1140.             }
  1141.  
  1142.         UpToDate = False;
  1143.         ListOfSongs->GetElement(Selection,&Temp);
  1144.         Temp.VolumeOverrideDefault = Flag;
  1145.         if (Flag)
  1146.             {
  1147.                 Temp.Volume = Volume;
  1148.                 SpecificVolumeBox->DoEnable();
  1149.                 SpecificVolumeText->DoEnable();
  1150.                 if (SpecificVolumeBox->GetValue() != Temp.Volume)
  1151.                     {
  1152.                         SpecificVolumeBox->SetValue(Temp.Volume);
  1153.                     }
  1154.             }
  1155.          else
  1156.             {
  1157.                 SpecificVolumeBox->DoDisable();
  1158.                 SpecificVolumeText->DoDisable();
  1159.                 if (Selection == Playing)
  1160.                     {
  1161.                         SendMessage((short)Volume,keyLoudness);
  1162.                     }
  1163.             }
  1164.         ListOfSongs->PutElement(Selection,&Temp);
  1165.     }
  1166.  
  1167.  
  1168. void                CMyDocument::SetDefaultStereoOn(MyBoolean NewStereoOn)
  1169.     {
  1170.         StereoOn = NewStereoOn;
  1171.         if (DefaultStereoOnBox->State != NewStereoOn)
  1172.             {
  1173.                 DefaultStereoOnBox->DoThang();
  1174.             }
  1175.         if (!OverrideStereoOnBox->State)
  1176.             {
  1177.                 if (SpecificStereoOnBox->State != NewStereoOn)
  1178.                     {
  1179.                         SpecificStereoOnBox->DoThang();
  1180.                     }
  1181.                 if (Selection == Playing)
  1182.                     {
  1183.                         SendMessage((short)NewStereoOn,keyStereoOn);
  1184.                     }
  1185.             }
  1186.         UpToDate = False;
  1187.     }
  1188.  
  1189.  
  1190. void                CMyDocument::SetDefaultAntiAliasing(MyBoolean NewAntiAliasing)
  1191.     {
  1192.         AntiAliasing = NewAntiAliasing;
  1193.         if (DefaultAntiAliasingBox->State != NewAntiAliasing)
  1194.             {
  1195.                 DefaultAntiAliasingBox->DoThang();
  1196.             }
  1197.         if (!OverrideAntiAliasingBox->State)
  1198.             {
  1199.                 if (SpecificAntiAliasingBox->State != NewAntiAliasing)
  1200.                     {
  1201.                         SpecificAntiAliasingBox->DoThang();
  1202.                     }
  1203.                 if (Selection == Playing)
  1204.                     {
  1205.                         SendMessage((short)NewAntiAliasing,keyAntiAliasing);
  1206.                     }
  1207.             }
  1208.         UpToDate = False;
  1209.     }
  1210.  
  1211.  
  1212. void                CMyDocument::SetDefaultSamplingRate(ulong NewSamplingRate)
  1213.     {
  1214.         SamplingRate = NewSamplingRate;
  1215.         if (DefaultSamplingRateBox->GetValue() != NewSamplingRate)
  1216.             {
  1217.                 DefaultSamplingRateBox->SetValue(NewSamplingRate);
  1218.             }
  1219.         if (!OverrideSamplingRateBox->State)
  1220.             {
  1221.                 if (SpecificSamplingRateBox->GetValue() != NewSamplingRate)
  1222.                     {
  1223.                         SpecificSamplingRateBox->SetValue(NewSamplingRate);
  1224.                     }
  1225.                 if (Selection == Playing)
  1226.                     {
  1227.                         SendMessage((short)NewSamplingRate,keySamplingRate);
  1228.                     }
  1229.             }
  1230.         UpToDate = False;
  1231.     }
  1232.  
  1233.  
  1234. void                CMyDocument::SetDefaultStereoMix(short NewStereoMix)
  1235.     {
  1236.         StereoMix = NewStereoMix;
  1237.         if (DefaultStereoMixBox->GetValue() != NewStereoMix)
  1238.             {
  1239.                 DefaultStereoMixBox->SetValue(NewStereoMix);
  1240.             }
  1241.         if (!OverrideStereoMixBox->State)
  1242.             {
  1243.                 if (SpecificStereoMixBox->GetValue() != NewStereoMix)
  1244.                     {
  1245.                         SpecificStereoMixBox->SetValue(NewStereoMix);
  1246.                     }
  1247.                 if (Selection == Playing)
  1248.                     {
  1249.                         SendMessage((short)NewStereoMix,keyStereoMix);
  1250.                     }
  1251.             }
  1252.         UpToDate = False;
  1253.     }
  1254.  
  1255.  
  1256. void                CMyDocument::SetDefaultNumRepeats(short NewNumRepeats)
  1257.     {
  1258.         NumRepeats = NewNumRepeats;
  1259.         if (DefaultNumRepeatsBox->GetValue() != NewNumRepeats)
  1260.             {
  1261.                 DefaultNumRepeatsBox->SetValue(NewNumRepeats);
  1262.             }
  1263.         if (!OverrideNumRepeatsBox->State)
  1264.             {
  1265.                 if (SpecificNumRepeatsBox->GetValue() != NewNumRepeats)
  1266.                     {
  1267.                         SpecificNumRepeatsBox->SetValue(NewNumRepeats);
  1268.                     }
  1269.                 if (Selection == Playing)
  1270.                     {
  1271.                         SendMessage((short)NewNumRepeats,keyNumRepeats);
  1272.                     }
  1273.             }
  1274.         UpToDate = False;
  1275.     }
  1276.  
  1277.  
  1278. void                CMyDocument::SetDefaultSpeed(short NewSpeed)
  1279.     {
  1280.         Speed = NewSpeed;
  1281.         if (DefaultSpeedBox->GetValue() != NewSpeed)
  1282.             {
  1283.                 DefaultSpeedBox->SetValue(NewSpeed);
  1284.             }
  1285.         if (!OverrideSpeedBox->State)
  1286.             {
  1287.                 if (SpecificSpeedBox->GetValue() != NewSpeed)
  1288.                     {
  1289.                         SpecificSpeedBox->SetValue(NewSpeed);
  1290.                     }
  1291.                 if (Selection == Playing)
  1292.                     {
  1293.                         SendMessage((short)NewSpeed,keySpeed);
  1294.                     }
  1295.             }
  1296.         UpToDate = False;
  1297.     }
  1298.  
  1299.  
  1300. void                CMyDocument::SetDefaultVolume(short NewVolume)
  1301.     {
  1302.         Volume = NewVolume;
  1303.         if (DefaultVolumeBox->GetValue() != NewVolume)
  1304.             {
  1305.                 DefaultVolumeBox->SetValue(NewVolume);
  1306.             }
  1307.         if (!OverrideVolumeBox->State)
  1308.             {
  1309.                 if (SpecificVolumeBox->GetValue() != NewVolume)
  1310.                     {
  1311.                         SpecificVolumeBox->SetValue(NewVolume);
  1312.                     }
  1313.                 if (Selection == Playing)
  1314.                     {
  1315.                         SendMessage((short)NewVolume,keyLoudness);
  1316.                     }
  1317.             }
  1318.         UpToDate = False;
  1319.     }
  1320.  
  1321.  
  1322. void                CMyDocument::SetAutoNextSong(MyBoolean NewAutoNextSong)
  1323.     {
  1324.         AutoNextSong = NewAutoNextSong;
  1325.         if (Playing != -1)
  1326.             {
  1327.                 PlayNextWhenThisOneStops = NewAutoNextSong;
  1328.             }
  1329.         if (AutoNextSongBox->State != NewAutoNextSong)
  1330.             {
  1331.                 AutoNextSongBox->DoThang();
  1332.             }
  1333.         UpToDate = False;
  1334.     }
  1335.  
  1336.  
  1337. void                CMyDocument::SetAutoStartSongs(MyBoolean NewAutoStartSongs)
  1338.     {
  1339.         AutoStartSongs = NewAutoStartSongs;
  1340.         if (AutoStartSongsBox->State != NewAutoStartSongs)
  1341.             {
  1342.                 AutoStartSongsBox->DoThang();
  1343.             }
  1344.         UpToDate = False;
  1345.     }
  1346.  
  1347.  
  1348. void                CMyDocument::SetRandomize(MyBoolean NewRandomize)
  1349.     {
  1350.         Randomize = NewRandomize;
  1351.         if (RandomizeBox->State != NewRandomize)
  1352.             {
  1353.                 RandomizeBox->DoThang();
  1354.             }
  1355.         UpToDate = False;
  1356.     }
  1357.  
  1358.  
  1359. void                CMyDocument::SetRepeat(MyBoolean NewRepeat)
  1360.     {
  1361.         Repeat = NewRepeat;
  1362.         if (RepeatBox->State != NewRepeat)
  1363.             {
  1364.                 RepeatBox->DoThang();
  1365.             }
  1366.         UpToDate = False;
  1367.     }
  1368.  
  1369.  
  1370. void                CMyDocument::DoRewind(MyBoolean Flag)
  1371.     {
  1372.         short                SpiffParam;
  1373.  
  1374.         if ((Playing != -1) && PlayerExists)
  1375.             {
  1376.                 if (Flag)
  1377.                     {
  1378.                         SpiffParam = '<';
  1379.                     }
  1380.                  else
  1381.                     {
  1382.                         SpiffParam = '|';
  1383.                     }
  1384.                 SendMessage(SpiffParam,keyKeyPressCharacter);
  1385.             }
  1386.     }
  1387.  
  1388.  
  1389. void                CMyDocument::DoStop(void)
  1390.     {
  1391.         if (Playing != -1)
  1392.             {
  1393.                 CancelCurrentSong();
  1394.             }
  1395.         ResetRandomPlayList();
  1396.         DeregisterIdler(this);
  1397.     }
  1398.  
  1399.  
  1400. void                CMyDocument::DoPlay(void)
  1401.     {
  1402.         SpecificSamplingRateBox->StoreValue();
  1403.         SpecificStereoMixBox->StoreValue();
  1404.         SpecificNumRepeatsBox->StoreValue();
  1405.         SpecificSpeedBox->StoreValue();
  1406.         SpecificVolumeBox->StoreValue();
  1407.         DefaultSamplingRateBox->StoreValue();
  1408.         DefaultStereoMixBox->StoreValue();
  1409.         DefaultNumRepeatsBox->StoreValue();
  1410.         DefaultSpeedBox->StoreValue();
  1411.         DefaultVolumeBox->StoreValue();
  1412.         /* this could either be invoked while playing but paused, or when nothing */
  1413.         /* is playing at all. */
  1414.         if (Playing == -1)
  1415.             {
  1416.                 /* nothing playing; start selected song */
  1417.                 if (Selection != -1)
  1418.                     {
  1419.                         StartThisSong(Selection);
  1420.                     }
  1421.                  else
  1422.                     {
  1423.                         if (Randomize)
  1424.                             {
  1425.                                 StartRandomSong();
  1426.                             }
  1427.                          else
  1428.                             {
  1429.                                 StartThisSong(0);
  1430.                             }
  1431.                     }
  1432.             }
  1433.          else
  1434.             {
  1435.                 CPauseButton*            PauseButton;
  1436.  
  1437.                 /* paused, resume playing */
  1438.                 if (PausePlayButton != NIL)
  1439.                     {
  1440.                         delete PausePlayButton;
  1441.                     }
  1442.                 PauseButton = new CPauseButton;
  1443.                 PausePlayButton = PauseButton;
  1444.                 PauseButton->IPauseButton(this,RootWindow);
  1445.                 if (!RootWindow->Suspended)
  1446.                     {
  1447.                         PauseButton->DoResume();
  1448.                     }
  1449.                 PauseButton->DoUpdate();
  1450.  
  1451.                 /* sending unpause event */
  1452.                 SendMessage(' ',keyKeyPressCharacter);
  1453.             }
  1454.     }
  1455.  
  1456.  
  1457. void                CMyDocument::DoPause(void)
  1458.     {
  1459.         if ((Playing != -1) && PlayerExists)
  1460.             {
  1461.                 CPlayButton*            PlayButton;
  1462.  
  1463.                 /* playing, pause song */
  1464.                 if (PausePlayButton != NIL)
  1465.                     {
  1466.                         delete PausePlayButton;
  1467.                     }
  1468.                 PlayButton = new CPlayButton;
  1469.                 PausePlayButton = PlayButton;
  1470.                 PlayButton->IPlayButton(this,RootWindow);
  1471.                 if (!RootWindow->Suspended)
  1472.                     {
  1473.                         PlayButton->DoResume();
  1474.                     }
  1475.                 PlayButton->DoUpdate();
  1476.  
  1477.                 /* sending pause event */
  1478.                 SendMessage(' ',keyKeyPressCharacter);
  1479.             }
  1480.     }
  1481.  
  1482.  
  1483. void                CMyDocument::DoFastForward(MyBoolean Flag)
  1484.     {
  1485.         short                SpiffParam;
  1486.  
  1487.         if ((Playing != -1) && PlayerExists)
  1488.             {
  1489.                 if (Flag)
  1490.                     {
  1491.                         SpiffParam = '>';
  1492.                     }
  1493.                  else
  1494.                     {
  1495.                         SpiffParam = '|';
  1496.                     }
  1497.                 SendMessage(SpiffParam,keyKeyPressCharacter);
  1498.             }
  1499.     }
  1500.  
  1501.  
  1502. void                CMyDocument::DoSkipToNext(void)
  1503.     {
  1504.         if (Playing != -1)
  1505.             {
  1506.                 if (Randomize)
  1507.                     {
  1508.                         StartRandomSong();
  1509.                     }
  1510.                  else
  1511.                     {
  1512.                         if (Playing < ListOfSongs->GetNumElements() - 1)
  1513.                             {
  1514.                                 StartThisSong(Playing + 1);
  1515.                             }
  1516.                          else
  1517.                             {
  1518.                                 StartThisSong(0);
  1519.                             }
  1520.                     }
  1521.             }
  1522.     }
  1523.  
  1524.  
  1525. void                CMyDocument::DoVolumeUp(void)
  1526.     {
  1527.         if ((Playing != -1) && PlayerExists)
  1528.             {
  1529.                 SendMessage('+',keyKeyPressCharacter);
  1530.             }
  1531.     }
  1532.  
  1533.  
  1534. void                CMyDocument::DoVolumeDown(void)
  1535.     {
  1536.         if ((Playing != -1) && PlayerExists)
  1537.             {
  1538.                 SendMessage('-',keyKeyPressCharacter);
  1539.             }
  1540.     }
  1541.  
  1542.  
  1543. void                CMyDocument::DoIdle(long Stupid)
  1544.     {
  1545.         CPauseButton*                    PauseButton;
  1546.         short                                    Error;
  1547.         AppleEvent                        Event;
  1548.         AEAddressDesc                    AddressDescriptor;
  1549.         AEDesc                                FileList;
  1550.         SongRec                                TheSong;
  1551.         AEDesc                                AEFileDescriptor;
  1552.         short                                    ShortInt;
  1553.         long                                    LongInt;
  1554.         Boolean                                BooleanValue;
  1555.         AEDesc                                TempDesc;
  1556.         AEDesc                                ListElement;
  1557.         long                                    OldPlayer;
  1558.         ProcessSerialNumber        OurPSN;
  1559.         PString                                NewWindowName;
  1560.         Handle                                String1,String2,String3;
  1561.  
  1562.         StackSizeTest();
  1563.         if ((!PlayerExists) && (SongToStart != -1))
  1564.             {
  1565.                 PlayerState = PlayerLaunching;
  1566.                 ListOfSongs->GetElement(SongToStart,&TheSong);
  1567.                 if (TheSong.Tracker)
  1568.                     {
  1569.                         Application->LaunchTracker(FRANKSEIDECREATOR);
  1570.                     }
  1571.                  else
  1572.                     {
  1573.                         Application->LaunchTracker(TRACKERSERVERCREATOR);
  1574.                     }
  1575.             }
  1576.         if (PlayerExists && (PlayerState == PlayerWaitingForInit))
  1577.             {
  1578.                 DeregisterIdler(this);
  1579.  
  1580.                 PlayerState = PlayerRunning;
  1581.                 OldPlayer = Playing;
  1582.                 Playing = SongToStart;
  1583.                 SongToStart = -1;
  1584.                 SongList->Redraw(OldPlayer,OldPlayer);
  1585.                 SongList->Redraw(Playing,Playing);
  1586.  
  1587.                 ListOfSongs->GetElement(Playing,&TheSong);
  1588.                 CheckHeap();
  1589.  
  1590.                 BeginStringOperation();
  1591.                 String1 = PString2Handle(TheFile.name);
  1592.                 RegisterString(String1);
  1593.                 String2 = GetCString(SeparatorID);
  1594.                 RegisterString(String2);
  1595.                 String3 = PString2Handle(TheSong.SongName);
  1596.                 RegisterString(String3);
  1597.                 String1 = ConStr(String1,String2);
  1598.                 String1 = ConStr(String1,String3);
  1599.                 EndStringOperation(String1);
  1600.                 Handle2PString(String1,NewWindowName);
  1601.                 ReleaseHandle(String1);
  1602.                 SetWTitle(RootWindow->MyGrafPtr,NewWindowName);
  1603.  
  1604.                 /* constructing nasty parameter block & sending open event to tracker */
  1605.                 HLock((Handle)this);
  1606.  
  1607.                 Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPlayer,
  1608.                     sizeof(ProcessSerialNumber),&AddressDescriptor);
  1609.  
  1610.                 Error = AECreateAppleEvent(kCoreEventClass,kAEOpenDocuments,&AddressDescriptor,
  1611.                     kAutoGenerateReturnID,kAnyTransactionID,&Event);
  1612.                 CheckHeap();
  1613.  
  1614.                 Error = AECreateList(NIL,0,False,&FileList);
  1615.                 HLock((Handle)TheSong.SongLocation);
  1616.                 AECreateDesc(typeAlias,(void*)*TheSong.SongLocation,
  1617.                     HandleSize((Handle)TheSong.SongLocation),&ListElement);
  1618.                 HUnlock((Handle)TheSong.SongLocation);
  1619.                 Error = AEPutDesc(&FileList,0,&ListElement);
  1620.                 Error = AEDisposeDesc(&ListElement);
  1621.                 Error = AEPutParamDesc(&Event,keyDirectObject,&FileList);
  1622.                 Error = AEDisposeDesc(&FileList);
  1623.  
  1624.                 if (TheSong.AntiAliasingOverrideDefault)
  1625.                     {
  1626.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.AntiAliasing,
  1627.                             sizeof(MyBoolean),&TempDesc);
  1628.                     }
  1629.                  else
  1630.                     {
  1631.                         Error = AECreateDesc(typeShortInteger,(void*)&AntiAliasing,
  1632.                             sizeof(MyBoolean),&TempDesc);
  1633.                     }
  1634.                 Error = AEPutParamDesc(&Event,keyAntiAliasing,&TempDesc);
  1635.                 Error = AEDisposeDesc(&TempDesc);
  1636.  
  1637.                 if (TheSong.StereoOnOverrideDefault)
  1638.                     {
  1639.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.StereoOn,
  1640.                             sizeof(MyBoolean),&TempDesc);
  1641.                     }
  1642.                  else
  1643.                     {
  1644.                         Error = AECreateDesc(typeShortInteger,(void*)&StereoOn,
  1645.                             sizeof(MyBoolean),&TempDesc);
  1646.                     }
  1647.                 Error = AEPutParamDesc(&Event,keyStereoOn,&TempDesc);
  1648.                 Error = AEDisposeDesc(&TempDesc);
  1649.  
  1650.                 if (TheSong.SamplingRateOverrideDefault)
  1651.                     {
  1652.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.SamplingRate,
  1653.                             sizeof(ushort),&TempDesc);
  1654.                     }
  1655.                  else
  1656.                     {
  1657.                         Error = AECreateDesc(typeShortInteger,(void*)&SamplingRate,
  1658.                             sizeof(ushort),&TempDesc);
  1659.                     }
  1660.                 Error = AEPutParamDesc(&Event,keySamplingRate,&TempDesc);
  1661.                 Error = AEDisposeDesc(&TempDesc);
  1662.  
  1663.                 if (TheSong.NumRepeatsOverrideDefault)
  1664.                     {
  1665.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.NumRepeats,
  1666.                             sizeof(short),&TempDesc);
  1667.                     }
  1668.                  else
  1669.                     {
  1670.                         Error = AECreateDesc(typeShortInteger,(void*)&NumRepeats,
  1671.                             sizeof(short),&TempDesc);
  1672.                     }
  1673.                 Error = AEPutParamDesc(&Event,keyNumRepeats,&TempDesc);
  1674.                 Error = AEDisposeDesc(&TempDesc);
  1675.  
  1676.                 if (TheSong.SpeedOverrideDefault)
  1677.                     {
  1678.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.Speed,
  1679.                             sizeof(short),&TempDesc);
  1680.                     }
  1681.                  else
  1682.                     {
  1683.                         Error = AECreateDesc(typeShortInteger,(void*)&Speed,
  1684.                             sizeof(short),&TempDesc);
  1685.                     }
  1686.                 Error = AEPutParamDesc(&Event,keySpeed,&TempDesc);
  1687.                 Error = AEDisposeDesc(&TempDesc);
  1688.  
  1689.                 if (TheSong.StereoMixOverrideDefault)
  1690.                     {
  1691.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.StereoMix,
  1692.                             sizeof(short),&TempDesc);
  1693.                     }
  1694.                  else
  1695.                     {
  1696.                         Error = AECreateDesc(typeShortInteger,(void*)&StereoMix,
  1697.                             sizeof(short),&TempDesc);
  1698.                     }
  1699.                 Error = AEPutParamDesc(&Event,keyStereoMix,&TempDesc);
  1700.                 Error = AEDisposeDesc(&TempDesc);
  1701.  
  1702.                 if (TheSong.VolumeOverrideDefault)
  1703.                     {
  1704.                         Error = AECreateDesc(typeShortInteger,(void*)&TheSong.Volume,
  1705.                             sizeof(short),&TempDesc);
  1706.                     }
  1707.                  else
  1708.                     {
  1709.                         Error = AECreateDesc(typeShortInteger,(void*)&Volume,
  1710.                             sizeof(short),&TempDesc);
  1711.                     }
  1712.                 Error = AEPutParamDesc(&Event,keyLoudness,&TempDesc);
  1713.                 Error = AEDisposeDesc(&TempDesc);
  1714.  
  1715.                 Error = GetCurrentProcess(&OurPSN);
  1716.                 Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPSN,
  1717.                     sizeof(ProcessSerialNumber),&TempDesc);
  1718.                 Error = AEPutParamDesc(&Event,keySenderPSN,&TempDesc);
  1719.                 Error = AEDisposeDesc(&TempDesc);
  1720.  
  1721.                 Application->SendMessage(OurPlayer,&Event);
  1722.                 Error = AEDisposeDesc(&AddressDescriptor);
  1723.                 Error = AEDisposeDesc(&Event);
  1724.                 HUnlock((Handle)this);
  1725.  
  1726.                 if (PausePlayButton != NIL)
  1727.                     {
  1728.                         delete PausePlayButton;
  1729.                     }
  1730.                 PauseButton = new CPauseButton;
  1731.                 PausePlayButton = PauseButton;
  1732.                 PauseButton->IPauseButton(this,RootWindow);
  1733.                 if (!RootWindow->Suspended)
  1734.                     {
  1735.                         PauseButton->DoResume();
  1736.                     }
  1737.                 PauseButton->DoUpdate();
  1738.  
  1739.                 StopButton->DoEnable();
  1740.                 RewindButton->DoEnable();
  1741.                 FastForwardButton->DoEnable();
  1742.                 SkipToNextButton->DoEnable();
  1743.             }
  1744.     }
  1745.  
  1746.  
  1747. void                CMyDocument::PlayerDiedNotification(void)
  1748.     {
  1749.         CPlayButton*        PlayButton;
  1750.         long                        OldPlayer;
  1751.  
  1752.         PlayerExists = False;
  1753.         OldPlayer = Playing;
  1754.         Playing = -1;
  1755.         HLock((Handle)this);
  1756.         SetWTitle(RootWindow->MyGrafPtr,TheFile.name);
  1757.         HUnlock((Handle)this);
  1758.         SongList->Redraw(OldPlayer,OldPlayer);
  1759.         if (PlayNextWhenThisOneStops)
  1760.             {
  1761.                 if (SongToStart == -1)
  1762.                     {
  1763.                         /* we want to hear the "next" song, but one was not specified. */
  1764.                         if (Randomize)
  1765.                             {
  1766.                                 StartRandomSong();
  1767.                             }
  1768.                          else
  1769.                             {
  1770.                                 if (OldPlayer < ListOfSongs->GetNumElements() - 1)
  1771.                                     {
  1772.                                         StartThisSong(OldPlayer + 1);
  1773.                                     }
  1774.                                  else
  1775.                                     {
  1776.                                         if (Repeat)
  1777.                                             {
  1778.                                                 StartThisSong(0);
  1779.                                             }
  1780.                                          else
  1781.                                             {
  1782.                                                 PlayNextWhenThisOneStops = False;
  1783.                                             }
  1784.                                     }
  1785.                             }
  1786.                     }
  1787.                  else
  1788.                     {
  1789.                         /* they DID specify which song to listen to next */
  1790.                         StartThisSong(SongToStart);
  1791.                     }
  1792.             }
  1793.  
  1794.         delete PausePlayButton;
  1795.         PlayButton = new CPlayButton;
  1796.         PlayButton->IPlayButton(this,RootWindow);
  1797.         PausePlayButton = PlayButton;
  1798.         if (!RootWindow->Suspended)
  1799.             {
  1800.                 PlayButton->DoResume();
  1801.             }
  1802.         PlayButton->DoUpdate();
  1803.  
  1804.         StopButton->DoDisable();
  1805.         RewindButton->DoDisable();
  1806.         FastForwardButton->DoDisable();
  1807.         SkipToNextButton->DoDisable();
  1808.     }
  1809.  
  1810.  
  1811. void                CMyDocument::PlayerLaunchedNotification(ProcessSerialNumber TheProcNum)
  1812.     {
  1813.         StackSizeTest();
  1814.         PlayerExists = True;
  1815.         PlayerState = PlayerWaitingForInit;
  1816.         OurPlayer = TheProcNum;
  1817.     }
  1818.  
  1819.  
  1820. void                CMyDocument::SetNewSelection(long NewSelection)
  1821.     {
  1822.         SpecificSamplingRateBox->StoreValue();
  1823.         SpecificStereoMixBox->StoreValue();
  1824.         SpecificNumRepeatsBox->StoreValue();
  1825.         SpecificSpeedBox->StoreValue();
  1826.         SpecificVolumeBox->StoreValue();
  1827.         DefaultSamplingRateBox->StoreValue();
  1828.         DefaultStereoMixBox->StoreValue();
  1829.         DefaultNumRepeatsBox->StoreValue();
  1830.         DefaultSpeedBox->StoreValue();
  1831.         DefaultVolumeBox->StoreValue();
  1832.         if (Selection != -1)
  1833.             {
  1834.                 long            SelectionTemp;
  1835.  
  1836.                 SelectionTemp = Selection;
  1837.                 Selection = -1;
  1838.                 SongList->Redraw(SelectionTemp,SelectionTemp);
  1839.             }
  1840.         Selection = NewSelection;
  1841.         if (NewSelection == -1)
  1842.             {
  1843.                 CStaticText*        StaticText;
  1844.                 LongPoint                Start,Extent;
  1845.  
  1846.                 SpecificStereoOnBox->DoDisable();
  1847.                 SpecificAntiAliasingBox->DoDisable();
  1848.                 SpecificSamplingRateBox->DoDisable();
  1849.                 SpecificStereoMixBox->DoDisable();
  1850.                 SpecificNumRepeatsBox->DoDisable();
  1851.                 SpecificSpeedBox->DoDisable();
  1852.                 SpecificVolumeBox->DoDisable();
  1853.                 SpecificTrackerBox->DoDisable();
  1854.                 SpecificSamplingRateText->DoDisable();
  1855.                 SpecificStereoMixText->DoDisable();
  1856.                 SpecificNumRepeatsText->DoDisable();
  1857.                 SpecificSpeedText->DoDisable();
  1858.                 SpecificVolumeText->DoDisable();
  1859.                 OverrideStereoOnBox->DoDisable();
  1860.                 OverrideAntiAliasingBox->DoDisable();
  1861.                 OverrideSamplingRateBox->DoDisable();
  1862.                 OverrideStereoMixBox->DoDisable();
  1863.                 OverrideNumRepeatsBox->DoDisable();
  1864.                 OverrideSpeedBox->DoDisable();
  1865.                 OverrideVolumeBox->DoDisable();
  1866.             }
  1867.          else
  1868.             {
  1869.                 LongPoint            Start,Extent;
  1870.                 Handle                String1;
  1871.                 Handle                String2;
  1872.                 Handle                String3;
  1873.                 Handle                String4;
  1874.                 SongRec                TheSong;
  1875.                 CPauseButton*    PauseButton;
  1876.                 CStaticText*    StaticText;
  1877.  
  1878.                 StackSizeTest();
  1879.                 SongList->Redraw(NewSelection,NewSelection);
  1880.                 ListOfSongs->GetElement(NewSelection,&TheSong);
  1881.  
  1882.                 OverrideStereoOnBox->DoEnable();
  1883.                 if (OverrideStereoOnBox->State != TheSong.StereoOnOverrideDefault)
  1884.                     {
  1885.                         OverrideStereoOnBox->DoThang();
  1886.                     }
  1887.                 if (TheSong.StereoOnOverrideDefault)
  1888.                     {
  1889.                         SpecificStereoOnBox->DoEnable();
  1890.                         if (SpecificStereoOnBox->State != TheSong.StereoOn)
  1891.                             {
  1892.                                 SpecificStereoOnBox->DoThang();
  1893.                             }
  1894.                     }
  1895.                  else
  1896.                     {
  1897.                         SpecificStereoOnBox->DoDisable();
  1898.                     }
  1899.  
  1900.                 OverrideAntiAliasingBox->DoEnable();
  1901.                 if (OverrideAntiAliasingBox->State != TheSong.AntiAliasingOverrideDefault)
  1902.                     {
  1903.                         OverrideAntiAliasingBox->DoThang();
  1904.                     }
  1905.                 if (TheSong.AntiAliasingOverrideDefault)
  1906.                     {
  1907.                         SpecificAntiAliasingBox->DoEnable();
  1908.                         if (SpecificAntiAliasingBox->State != TheSong.AntiAliasing)
  1909.                             {
  1910.                                 SpecificAntiAliasingBox->DoThang();
  1911.                             }
  1912.                     }
  1913.                  else
  1914.                     {
  1915.                         SpecificAntiAliasingBox->DoDisable();
  1916.                     }
  1917.  
  1918.                 OverrideSamplingRateBox->DoEnable();
  1919.                 if (OverrideSamplingRateBox->State != TheSong.SamplingRateOverrideDefault)
  1920.                     {
  1921.                         OverrideSamplingRateBox->DoThang();
  1922.                     }
  1923.                 if (TheSong.SamplingRateOverrideDefault)
  1924.                     {
  1925.                         SpecificSamplingRateBox->DoEnable();
  1926.                         SpecificSamplingRateText->DoEnable();
  1927.                         SpecificSamplingRateBox->SetValue(TheSong.SamplingRate);
  1928.                     }
  1929.                  else
  1930.                     {
  1931.                         SpecificSamplingRateBox->DoDisable();
  1932.                         SpecificSamplingRateText->DoDisable();
  1933.                     }
  1934.  
  1935.                 OverrideStereoMixBox->DoEnable();
  1936.                 if (OverrideStereoMixBox->State != TheSong.StereoMixOverrideDefault)
  1937.                     {
  1938.                         OverrideStereoMixBox->DoThang();
  1939.                     }
  1940.                 if (TheSong.StereoMixOverrideDefault)
  1941.                     {
  1942.                         SpecificStereoMixBox->DoEnable();
  1943.                         SpecificStereoMixText->DoEnable();
  1944.                         SpecificStereoMixBox->SetValue(TheSong.StereoMix);
  1945.                     }
  1946.                  else
  1947.                     {
  1948.                         SpecificStereoMixBox->DoDisable();
  1949.                         SpecificStereoMixText->DoDisable();
  1950.                     }
  1951.  
  1952.                 OverrideNumRepeatsBox->DoEnable();
  1953.                 if (OverrideNumRepeatsBox->State != TheSong.NumRepeatsOverrideDefault)
  1954.                     {
  1955.                         OverrideNumRepeatsBox->DoThang();
  1956.                     }
  1957.                 if (TheSong.NumRepeatsOverrideDefault)
  1958.                     {
  1959.                         SpecificNumRepeatsBox->DoEnable();
  1960.                         SpecificNumRepeatsText->DoEnable();
  1961.                         SpecificNumRepeatsBox->SetValue(TheSong.NumRepeats);
  1962.                     }
  1963.                  else
  1964.                     {
  1965.                         SpecificNumRepeatsBox->DoDisable();
  1966.                         SpecificNumRepeatsText->DoDisable();
  1967.                     }
  1968.  
  1969.                 OverrideSpeedBox->DoEnable();
  1970.                 if (OverrideSpeedBox->State != TheSong.SpeedOverrideDefault)
  1971.                     {
  1972.                         OverrideSpeedBox->DoThang();
  1973.                     }
  1974.                 if (TheSong.SpeedOverrideDefault)
  1975.                     {
  1976.                         SpecificSpeedBox->DoEnable();
  1977.                         SpecificSpeedText->DoEnable();
  1978.                         SpecificSpeedBox->SetValue(TheSong.Speed);
  1979.                     }
  1980.                  else
  1981.                     {
  1982.                         SpecificSpeedBox->DoDisable();
  1983.                         SpecificSpeedText->DoDisable();
  1984.                     }
  1985.  
  1986.                 OverrideVolumeBox->DoEnable();
  1987.                 if (OverrideVolumeBox->State != TheSong.VolumeOverrideDefault)
  1988.                     {
  1989.                         OverrideVolumeBox->DoThang();
  1990.                     }
  1991.                 if (TheSong.VolumeOverrideDefault)
  1992.                     {
  1993.                         SpecificVolumeBox->DoEnable();
  1994.                         SpecificVolumeText->DoEnable();
  1995.                         SpecificVolumeBox->SetValue(TheSong.Volume);
  1996.                     }
  1997.                  else
  1998.                     {
  1999.                         SpecificVolumeBox->DoDisable();
  2000.                         SpecificVolumeText->DoDisable();
  2001.                     }
  2002.  
  2003.                 SpecificTrackerBox->DoEnable();
  2004.                 if (SpecificTrackerBox->State != TheSong.Tracker)
  2005.                     {
  2006.                         SpecificTrackerBox->DoThang();
  2007.                     }
  2008.             }
  2009.     }
  2010.  
  2011.  
  2012. void                CMyDocument::MoveSong(long SongIndex, long NewIndex)
  2013.     {
  2014.         SongRec            MySong;
  2015.         long                OldSelection;
  2016.         long                Temp;
  2017.  
  2018.         UpToDate = False;
  2019.         SpecificSamplingRateBox->StoreValue();
  2020.         SpecificStereoMixBox->StoreValue();
  2021.         SpecificNumRepeatsBox->StoreValue();
  2022.         SpecificSpeedBox->StoreValue();
  2023.         SpecificVolumeBox->StoreValue();
  2024.         DefaultSamplingRateBox->StoreValue();
  2025.         DefaultStereoMixBox->StoreValue();
  2026.         DefaultNumRepeatsBox->StoreValue();
  2027.         DefaultSpeedBox->StoreValue();
  2028.         DefaultVolumeBox->StoreValue();
  2029.  
  2030.         OldSelection = Playing;
  2031.         Playing = -1;
  2032.         SongList->Redraw(OldSelection,OldSelection);
  2033.         Playing = OldSelection;
  2034.         if (Playing == SongIndex)
  2035.             {
  2036.                 Playing = NewIndex;
  2037.                 if (NewIndex > SongIndex)
  2038.                     {
  2039.                         Playing -= 1;
  2040.                     }
  2041.             }
  2042.          else
  2043.             {
  2044.                 if (SongIndex < NewIndex)
  2045.                     {
  2046.                         if ((Playing > SongIndex) && (Playing < NewIndex))
  2047.                             {
  2048.                                 Playing -= 1;
  2049.                             }
  2050.                     }
  2051.                  else
  2052.                     {
  2053.                         if ((Playing >= NewIndex) && (Playing < SongIndex))
  2054.                             {
  2055.                                 Playing += 1;
  2056.                             }
  2057.                     }
  2058.             }
  2059.         SongList->Redraw(Playing,Playing);
  2060.  
  2061.         OldSelection = Selection;
  2062.         Selection = -1;
  2063.         SongList->Redraw(OldSelection,OldSelection);
  2064.         if ((SongIndex < 0) || (SongIndex >= ListOfSongs->GetNumElements()))
  2065.             {
  2066.                 return;
  2067.             }
  2068.         if (NewIndex < 0)
  2069.             {
  2070.                 NewIndex = 0;
  2071.             }
  2072.         ListOfSongs->GetElement(SongIndex,&MySong);
  2073.         ListOfSongs->DeleteElement(SongIndex);
  2074.         if (NewIndex > SongIndex)
  2075.             {
  2076.                 NewIndex -= 1;
  2077.             }
  2078.         NewIndex = ListOfSongs->InsertElement(NewIndex);
  2079.         ListOfSongs->PutElement(NewIndex,&MySong);
  2080.         Selection = NewIndex;
  2081.         if (SongIndex > NewIndex)
  2082.             {
  2083.                 Temp = SongIndex;
  2084.                 SongIndex = NewIndex;
  2085.                 NewIndex = Temp;
  2086.             }
  2087.         SongList->Redraw(SongIndex,NewIndex);
  2088.     }
  2089.  
  2090.  
  2091. void                CMyDocument::ResetRandomPlayList(void)
  2092.     {
  2093.         long                Scan;
  2094.         long                End;
  2095.         SongRec            Temp;
  2096.  
  2097.         End = ListOfSongs->GetNumElements();
  2098.         for (Scan = 0; Scan < End; Scan += 1)
  2099.             {
  2100.                 ListOfSongs->GetElement(Scan,&Temp);
  2101.                 Temp.PlayedFlag = False;
  2102.                 ListOfSongs->PutElement(Scan,&Temp);
  2103.             }
  2104.     }
  2105.  
  2106.  
  2107. void                CMyDocument::StartRandomSong(void)
  2108.     {
  2109.         short                RunoutCount;
  2110.         long                Possibility;
  2111.         long                NumSongs;
  2112.         SongRec            Temp;
  2113.         long                StartingPoint;
  2114.  
  2115.         /* randomly look for a song that hasn't been played.  If we */
  2116.         /* can't find one then do a linear search for one.  If we fail that */
  2117.         /* then there are no more: reset and play if <repeat> is on, otherwise */
  2118.         /* just stop. */
  2119.         CancelCurrentSong();
  2120.      TryAgainPoint:
  2121.         NumSongs = ListOfSongs->GetNumElements();
  2122.         if (NumSongs == 0)
  2123.             {
  2124.                 return; /* oops, can't play anything */
  2125.             }
  2126.         RunoutCount = MAXRANDOMTRIESBEFOREGIVINGUP;
  2127.         while (RunoutCount > 0)
  2128.             {
  2129.                 Possibility = ((unsigned short)Random()) % NumSongs;
  2130.                 ListOfSongs->GetElement(Possibility,&Temp);
  2131.                 if (!Temp.PlayedFlag)
  2132.                     {
  2133.                         /* found one to play */
  2134.                      FoundOnePoint:
  2135.                         StartThisSong(Possibility);
  2136.                         return;
  2137.                     }
  2138.                 RunoutCount -= 1;
  2139.             }
  2140.         /* failed random search.  Do linear search */
  2141.         StartingPoint = Possibility;
  2142.         do
  2143.             {
  2144.                 Possibility += 1;
  2145.                 if (Possibility >= NumSongs)
  2146.                     {
  2147.                         Possibility = 0;
  2148.                     }
  2149.                 ListOfSongs->GetElement(Possibility,&Temp);
  2150.                 if (!Temp.PlayedFlag)
  2151.                     {
  2152.                         goto FoundOnePoint;
  2153.                     }
  2154.             } while (Possibility != StartingPoint);
  2155.         /* failed that!  Reset and try again. */
  2156.         if (Repeat)
  2157.             {
  2158.                 /* there is no possible way to get into an infinite loop. */
  2159.                 ResetRandomPlayList();
  2160.                 goto TryAgainPoint;
  2161.             }
  2162.     }
  2163.  
  2164.  
  2165. /* this sends control events to the remote player.  Note that it only */
  2166. /* supports short integer messages, but that's ok because they're all shorts */
  2167. void                CMyDocument::SendMessage(short TheMessage, DescType TheKeyWord)
  2168.     {
  2169.         short                        Error;
  2170.         AppleEvent            Event;
  2171.         AEAddressDesc        AddressDescriptor;
  2172.         short                        KeyPress;
  2173.  
  2174.         HLock((Handle)this); /* make sure the OurPlayer variable doesn't move */
  2175.         Error = AECreateDesc(typeProcessSerialNumber,(void*)&OurPlayer,
  2176.             sizeof(ProcessSerialNumber),&AddressDescriptor);
  2177.         HUnlock((Handle)this);
  2178.         Error = AECreateAppleEvent(ControlEventClass,ControlEvent,&AddressDescriptor,
  2179.             kAutoGenerateReturnID,kAnyTransactionID,&Event);
  2180.         Error = AEPutParamPtr(&Event,TheKeyWord,typeShortInteger,
  2181.             (void*)&TheMessage,sizeof(short));
  2182.         Application->SendMessage(OurPlayer,&Event);
  2183.         Error = AEDisposeDesc(&AddressDescriptor);
  2184.         Error = AEDisposeDesc(&Event);
  2185.         HUnlock((Handle)this);
  2186.     }
  2187.